#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require

#include "../../../../core/shader_binding_ID.h"
#include "../../../../core/shader_color.h"


layout(location = 0) in vec4 vColor;
layout(location = 1) in flat int vUV;
layout(location = 2) in flat uint vDrawType;
layout(location = 3) in flat float vDepthOffset;
layout(location = 4) in flat float vIntensity;

layout(location=0) out vec4 outColor;


layout(binding = DEF_BINDING_WIDGET_Texture) uniform sampler2DArray tex;

void main(void){
	vec2 r = gl_PointCoord * 1.2;
	outColor = texture(tex, vec3(r - 0.1, vUV), 0);

	switch(vDrawType){
		
		case DEF_DrawType_ICO_Color:
			outColor.rgb = outColor.rgb * vColor.rgb;
			break;

		case DEF_DrawType_ICO_CircularBackground: {
			r = (gl_PointCoord - 0.5);
			float a = (dot(r, r));
			a = clamp(0.5 - a - 0.25, 0.0, 0.25) * 20;
			
			vec4 background = vec4(vColor.rgb, a);
			outColor.rgb = mix(background.rgb, outColor.rgb + vIntensity, outColor.a);
			outColor.a = background.a;
			//outColor.rgb = vec3(a);
			break;
		}

		case DEF_DrawType_Col_CircularBackground : {
			r = (gl_PointCoord - 0.5);
			float a = (dot(r, r));
			a = clamp(0.5 - a - 0.25, 0.0, 0.25) * 20;

			outColor = vec4(vColor.rgb, a);
			break;
		}

		case DEF_DrawType_ICO_ColorInvert:
		default:
			outColor.rgb = (vec3(1.0) - outColor.rgb) * vColor.rgb;
			break;

	}
	if(outColor.a <= 0.01){
		discard;
	}
	
	gl_FragDepth = gl_FragCoord.z + vDepthOffset;
}


 